package com.topwater.topwater.controller;

import com.topwater.topwater.entity.SyMenu;
import com.topwater.topwater.service.SyMenuService;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import javax.annotation.Resource;
import com.topwater.topwater.utils.ResponseData;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
/**
 * (SyMenu)表控制层
 * @author 胡文
 * @since 2023-08-24 09:18:15 生成
 */
@RestController
@RequestMapping("syMenu")
@Api(tags = "SyMenu模块接口说明")
public class SyMenuController {
    /**
     * 服务对象
     */
    @Autowired
    private SyMenuService syMenuService;
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary ="通过id查询SyMenu数据的方法")
    @GetMapping(value="{id}", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryById(@PathVariable("id") Integer id) {
        return ResponseData.ok().putDataValue("obj",this.syMenuService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param syMenu 实体
     * @return 新增结果
     */
    @Operation(summary ="添加SyMenu表")
    @PostMapping(value="add", produces = {"application/json;charset=UTF-8"})
    public ResponseData add(SyMenu syMenu) {
        return ResponseData.ok().putDataValue("obj",this.syMenuService.insert(syMenu));
    }
    /**
     * 新增数据
     *
     * @param syMenu 实体
     * @return 新增结果
     */
    @Operation(summary ="添加SyMenu表")
    @PostMapping(value="addNotNull", produces = {"application/json;charset=UTF-8"})
    public ResponseData addNotNull(SyMenu syMenu) {
        return ResponseData.ok().putDataValue("obj",this.syMenuService.insertNotNull(syMenu));
    }
    /**
     * 编辑数据
     *
     * @param syMenu 实体
     * @return 编辑结果
     */
    @Operation(summary ="修改SyMenu表,根据id修改")
    @PostMapping(value="update", produces = {"application/json;charset=UTF-8"})
    public ResponseData update(SyMenu syMenu) {
        return ResponseData.ok().putDataValue("obj",this.syMenuService.update(syMenu));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Operation(summary ="删除SyMenu,根据id删除")
    @PostMapping(value="deleteById", produces = {"application/json;charset=UTF-8"})
    public ResponseData deleteById(Integer id) {
        return ResponseData.ok().putDataValue("obj",this.syMenuService.deleteById(id));
    }
    
    //单字符串全部模糊查询 带分页
    @Operation(summary ="模糊查询SyMenu 分页,一个字符串模糊查所有列")
    @GetMapping(value="queryByLike2",produces = {"application/json;charset=UTF-8"})
    public ResponseData queryByLike2(String str,
                            @ApiParam("第几页")
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @ApiParam("每页多少条")
                             @RequestParam(defaultValue = "10",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);
        List<SyMenu> list = this.syMenuService.queryByLike2(str);
        PageInfo pageInfo = new PageInfo<SyMenu>(list,7);
        return ResponseData.ok().putDataValue("pageInfo",pageInfo);
   }
  //带分页的模糊查询
    @Operation(summary ="带分页的模糊查询SyMenu ,主要用这个即可")
    @GetMapping(value="queryByLike",produces = {"application/json;charset=UTF-8"})
    public ResponseData queryByLike(SyMenu syMenu,
                            @ApiParam("第几页")
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @ApiParam("每页多少条")
                             @RequestParam(defaultValue = "10",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);
        List<SyMenu> list = this.syMenuService.queryByLike(syMenu);
        PageInfo pageInfo = new PageInfo<SyMenu>(list,7);
        return ResponseData.ok().putDataValue("pageInfo",pageInfo);
   }

}

